var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
  * 页面的初始数据
  */
  data: {
    radio: ''
  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    var that=this;
    var storeId = app.globalData.storeId;
    var data={
    };
    req.storeRequest("请稍等", "POST", url.store['getFractionProportion'], storeId, data, function back(res) {
      if(res.data!=null){
        that.setData({
          radio:res.data*100
        })
      }
    })
  },

  /**
  * 得到设置比率
  */
  getRatio: function (e) {
    var radio;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于两位数字
      radio = e.detail.value;
    } else {
      radio = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      radio: radio
    })
  },

  /**
  * 设置积分比率
  */
  setRatio: function () {
    var that = this;
    var radio = that.data.radio;
    if(radio==0){
      wx.showToast({
        icon:'none',
        title: '请输入正确积分比例',
      })
      return;
    }
    else if (parseInt(radio) > 100 || parseInt(radio) < 0) {
      wx.showToast({
        icon:'none',
        title: '请输入1~100的整数',
      })
      return
    }
    var proportion = (this.data.radio) / 100;
    console.log(proportion);
    var data = {
      proportion: proportion
    }
    var storeId = app.globalData.storeId;
    req.storeRequest("请稍等", "POST",url.store["setFractionProportion"], storeId, data, function back(res) {
      wx.showToast({
        icon : 'none',
        title: res.msg
      })
    })
  }
})